package cn.dduan.fool.collection.list;


import cn.hutool.core.date.StopWatch;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * LinkedList
 * <p>
 * 优点: 底层数据结构是链表，查询慢，增删快
 * <p>
 * 缺点: 线程不安全，效率高
 *
 * @author dduan
 * @version 1.0
 * @date 2023/3/27
 */
public class MyLinkedList {
    public static void main(String[] args) {
        StopWatch sw = new StopWatch("list 集合新增耗时");

        List<Integer> list = new LinkedList<>();
        sw.start("LinkedList");
        for (int i = 0; i < 100000; i++) {
            list.add(i);
        }
        sw.stop();
        System.out.println(sw.getTotalTimeSeconds());

        // 清空list
        list = new ArrayList<>();

        sw.start("ArrayList");
        for (int i = 0; i < 100000; i++) {
            list.add(i);
        }
        sw.stop();
        System.out.println(sw.getTotalTimeSeconds());
        System.out.println(sw.prettyPrint());
    }
}
